package com.wbc.utils.wbcBeanUtil.Demo;

import com.wbc.utils.wbcBeanUtil.WbcBeanConvertUtil;

import java.math.BigDecimal;
import java.util.Date;
import java.util.Map;

/**
 * @Author: wangbingchen
 * @Date: 2024/5/14 21:25
 * @Description:
 **/
public class TestRun {

    public static void main(String[] args) {
        //测试对象转对象
        Person person = new Person();
        person.setName("张三");
        person.setAge(25);
        person.setAddress("北京市");
        //测试把 person 对象转为 personDto 对象
        PersonDto convert = WbcBeanConvertUtil.mergeObjects(PersonDto.class,person);
        System.out.println(convert); //PersonDto{name='张三', age=25, address='北京市'}

        //测试 person 对象转为 personDto1 对象 因为属性只有一个是一样的 所以只会有一个属性被赋值
        PersonDto1 convert1 = WbcBeanConvertUtil.mergeObjects(PersonDto1.class, person);
        System.out.println(convert1); //PersonDto1{name1='null', age1=0, address='北京市'}

        //测试 person 对象转为 personDto2 对象 因为属性只有一个是一样的 但是不一样的有注解注解值匹配了
        PersonDto2 convert2 = WbcBeanConvertUtil.mergeObjects(PersonDto2.class, person);
        System.out.println(convert2); //PersonDto1{name1='张三', age1=25, address='北京市'}


        Person2 person2 = new Person2();
        person2.setSalary(new BigDecimal("3.2"));
        person2.setBirthDate(new Date());
        //测试一个对象或者多个对象转为 map
        Map<String, Object> stringObjectMap = WbcBeanConvertUtil.mergeObjectsToMap(person, person2);
        System.out.println(stringObjectMap);//{address=北京市, name=张三, salary=3.2, birthDate=Tue May 14 21:48:14 CST 2024, age=25}

        //测试 map 转为对象
        AllPerson allPerson = WbcBeanConvertUtil.convertMapToObject(stringObjectMap, AllPerson.class);
        System.out.println(allPerson);//AllPerson{name='张三', age=25, address='北京市', birthDate=Tue May 14 21:48:14 CST 2024, salary=3.2}

        //测试两个一样的对象合成map
        Person person3 = new Person();
        person3.setName("张232131");
        person3.setAge(26);
        person3.setAddress("上海市");
        Map<String, Object> stringObjectMap1 = WbcBeanConvertUtil.mergeObjectsToMap(person3, person);
        System.out.println(stringObjectMap1);//Person{name='张三', age=26, address='上海市'}

        //测试map转对象
        PersonT personT = WbcBeanConvertUtil.convertMapToObject(stringObjectMap1, PersonT.class);
        System.out.println(personT);

        //测试多个对象合成一个对象
        PersonT convert3 = WbcBeanConvertUtil.mergeObjects(PersonT.class, person3, person);
        System.out.println(convert3);

    }
}
